package com.eastmoney.emis.edda.infrastructure.bankname.repository;

import com.eastmoney.emis.edda.infrastructure.bankname.mapper.BankMapper;
import com.eastmoney.emis.edda.infrastructure.bankname.po.BankPo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @description: Description
 * @projectName: EDDA-HSBC
 * @package: com.eastmoney.emis.edda.infrastructure.bankname.repository
 * @author: 汪程程
 * @date: 2022/10/20 10:41 AM
 * @version: 1.0
 */
@Repository
public class BankRepositoryImpl implements BankRepository {

    @Autowired
    private BankMapper mapper;

    @Override
    public Map<String, String> getSupportBankCodeNameMap() {
        List<BankPo> bankPos = mapper.findAllActive();
        return bankPos.stream()
                .filter(r -> r.BANKSHORTNAME != null)
                .reduce(new ConcurrentHashMap<>(), (map, bankPo) -> {
                    String[] bankCodes = bankPo.BANKCODE.split(",");
                    for (String bankCode : bankCodes) {
                        map.put(bankCode, bankPo.BANKSHORTNAME);
                    }
                    return map;
                }, (k1, k2) -> k2);
    }
}
